package com.bjwl.wybx.service.impl;

import com.bjwl.wybx.VO.UserLoginVO;
import com.bjwl.wybx.VO.UserQueryVO;
import com.bjwl.wybx.VO.UserRegisterVO;
import com.bjwl.wybx.VO.UserUpdateVO;
import com.bjwl.wybx.entity.Role;
import com.bjwl.wybx.entity.User;
import com.bjwl.wybx.exception.SysException;
import com.bjwl.wybx.mapper.RoleMapper;
import com.bjwl.wybx.mapper.UserMapper;
import com.bjwl.wybx.service.UserService;
import com.bjwl.wybx.util.CurrUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public CurrUser login(UserLoginVO userLoginVO) {
        CurrUser currUser=new CurrUser();
        try {

            User user = userMapper.queryByUIdAndUPwd(userLoginVO);
            //获取ro_id
            Integer ro_id = userMapper.queryRoIdByuId(userLoginVO.getU_id());
            System.out.println("ro_id"+ro_id);
            //获取角色信息
            Role role = roleMapper.queryByRoId(ro_id);
            System.out.println("role:"+role);
            currUser.setU_id(user.getU_id());
            currUser.setU_name(user.getU_name());
            if (role!=null){
                currUser.setRo_id(role.getRo_id());
                currUser.setRo_name(role.getRo_name());
                currUser.setRo_status(role.getRo_status());
            }


        } catch (Exception e) {
            e.printStackTrace();
            throw new SysException("系统错误");
        }
        return currUser;
    }

    @Override
    public int add(UserRegisterVO userRegisterVO) {

        return 0;
    }

    @Override
    public int deleteUser(Integer repaire_id) {
        return 0;
    }

    @Override
    public int updateUser(UserUpdateVO userUpdateVO) {
        return 0;
    }

    @Override
    public List<UserQueryVO> query() {
        return null;
    }
}
